package com.jia.lidao.others.enity;

import android.util.Log;

import com.google.gson.reflect.TypeToken;
import com.jia.lidao.others.utils.GsonUtils;
import com.zhy.http.okhttp.callback.Callback;

import okhttp3.Call;
import okhttp3.Response;

public abstract class ObjectCallBack<T>  extends Callback<T> {

    private TypeToken<T> type;

    public ObjectCallBack(TypeToken<T> type) {
        this.type = type;
    }

    @Override
    public T parseNetworkResponse(Response response, int id) throws Exception {

            String json = response.body().string();
            T result = null;
            if (json != null) {
                Log.d("parseNetworkResponse","response=" + json.replaceAll(" ", "").replaceAll("\n", ""));
                result = GsonUtils.fromJson(json, type);
            }


            return result;
}

    public abstract void onError(Call call, Exception e, int id);
}